package com.library.collection.service;

import com.library.collection.dao.CollectionDaoImpl;
import com.library.entity.Collection;
import com.library.entity.Staff;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional(readOnly=false)
public class CollectionServiceImpl {
	
	@Resource
	private CollectionDaoImpl collectionDaoImpl;

	public void addCollection(Collection collection){
		this.collectionDaoImpl.saveCollection(collection);
	}

    @Transactional(readOnly=true)
	public Collection getCollectionById(Integer collectionId)
	{
		return this.collectionDaoImpl.getCollectionById(collectionId);
	}

    @Transactional(readOnly = true)
	public Collection getCollectionByStaff(Staff staff){
		return this.getCollectionById(staff.getCollection().getCollectionId());
	}

	public void updateCollection(Collection collection){
		this.collectionDaoImpl.updateCollection(collection);
	}


	/*删除指定评价记录*/
	public void deleteCollection(int collectionId){
		Collection collection = this.getCollectionById(collectionId);
		this.collectionDaoImpl.deleteCollection(collection);
    }
}
